package com.sinosoft.hydra.um.helper;

import com.sinosoft.hydra.um.LoginUser;

public class AuthContextHelper {

    private static ThreadLocal<LoginUser> authContextHolder = new ThreadLocal<LoginUser>();
    private static ThreadLocal<Long> timeHolder = new ThreadLocal<Long>();

    public static LoginUser getLoginUser() {
        return (LoginUser) authContextHolder.get();
    }

    public static void setLoginUser(LoginUser loginUser) {
        authContextHolder.set(loginUser);
    }

    public static long getTime() {
        Long obj = timeHolder.get();
        return obj == null ? -1 : obj;
    }

    public static void setTime(long times) {
        timeHolder.set(times);
    }

    public static void destroy() {
        authContextHolder.remove();
        authContextHolder = null;
        timeHolder.remove();
        timeHolder = null;
    }
}
